var deviceone = require("deviceone");
var global = deviceone.sm("do_Global");
var cacher = deviceone.sm("do_DataCache");

/** 获取当前访问社区id **/
var mapKey_communityVisitId = "communityVisitId";
function communityVisitId(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_communityVisitId)){
			var value = cacher.loadData(mapKey_communityVisitId);
			if(!value || value==null || value==="undefined"){
				return "";
			}
			return value;
		}else{
			return "";
		}
    }
    if(arguments[0]===""){
    	cacher.removeData(mapKey_communityVisitId);
        return;
    }
    cacher.saveData(mapKey_communityVisitId,""+arguments[0]);
};
module.exports.communityVisitId = communityVisitId;
module.exports.communityVisitIdKey = function(){
	return mapKey_communityVisitId;
};

/** 是否是从起始页进来的(为使用者IM的在其它设备的监听事件):1-是,其它-否 **/
var mapKey_isFromStartup = "isFromStartup";
function isFromStartup(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_isFromStartup)){
			var value = cacher.loadData(mapKey_isFromStartup);
			if(!value || value==null || value==="undefined"){
				return "";
			}
			return value;
		}else{
			return "";
		}
    }
    if(arguments[0]===""){
    	cacher.removeData(mapKey_isFromStartup);
        return;
    }
    cacher.saveData(mapKey_isFromStartup,""+arguments[0]);
};
module.exports.isFromStartup = isFromStartup;

/** 是否(安装后)第一次打开app:1-是,其它-否 **/
var mapKey_firstTimeOpen = "firstTimeOpen";
function firstTimeOpen(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_firstTimeOpen)){
			var value = cacher.loadData(mapKey_firstTimeOpen);
			if(!value || value==null || value==="undefined"){
				return "";
			}
			return value;
		}else{
			return "";
		}
    }
    if(arguments[0]===""){
    	cacher.removeData(mapKey_firstTimeOpen);
        return;
    }
    cacher.saveData(mapKey_firstTimeOpen,""+arguments[0]);
};
module.exports.firstTimeOpen = firstTimeOpen;

/** 是否已打开了更新页面:1-是,其它-否 **/
var mapKey_upgradePage_isOpen = "upgradePage_isOpen";
function upgradePageIsOpen(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_upgradePage_isOpen)){
			var value = cacher.loadData(mapKey_upgradePage_isOpen);
			if(!value || value==null || value==="undefined"){
				return "";
			}
			return value;
		}else{
			return "";
		}
    }
    if(arguments[0]===""){
    	cacher.removeData(mapKey_upgradePage_isOpen);
        return;
    }
    cacher.saveData(mapKey_upgradePage_isOpen,""+arguments[0]);
};
module.exports.upgradePageIsOpen = upgradePageIsOpen;

var mapKey_upgradeDataJsonStr = "upgradeDataJsonStr";
function upgradeDataJsonStr(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_upgradeDataJsonStr)){
			var value = cacher.loadData(mapKey_upgradeDataJsonStr);
			if(!value || value==null || value==="undefined"){
				return "";
			}
			return value;
		}else{
			return "";
		}
    }
    if(arguments[0]===""){
    	cacher.removeData(mapKey_upgradeDataJsonStr);
        return;
    }
    cacher.saveData(mapKey_upgradeDataJsonStr,""+arguments[0]);
};
module.exports.upgradeDataJsonStr = upgradeDataJsonStr;

var mapKey_currentContentVersion = "currentContentVersionKey";
function currentContentVersion(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_currentContentVersion)){
			var value = cacher.loadData(mapKey_currentContentVersion);
			if(!value || value==null || value==="undefined"){
				return "";
			}else{
				return value;
			}
		}else{
			var appVer = global.getVersion();
			var nativeVersion = appVer.ver;
			cacher.saveData(mapKey_currentContentVersion,""+nativeVersion);
			return nativeVersion;
		}
    }
    if(arguments[0]===""){
    	cacher.removeData(mapKey_currentContentVersion);
        return;
    }
    cacher.saveData(mapKey_currentContentVersion,""+arguments[0]);
};
module.exports.currentContentVersion = currentContentVersion;

function currentNativeVersion(){
	var appVer = global.getVersion();
	var nativeVersion = appVer.ver;
	return nativeVersion;
}
module.exports.currentNativeVersion = currentNativeVersion;

var mapKey_upgradeStatus = "upgradeStatusKey";
//安装状态:1-未安装;2-安装中;
function upgradeStatus(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_upgradeStatus)){
			var value = cacher.loadData(mapKey_upgradeStatus);
			if(!value || value==null || value==="undefined"){
				return "";
			}
			return value;
		}
  }
  if(arguments[0]===""){
  	cacher.removeData(mapKey_upgradeStatus);
      return;
  }
  cacher.saveData(mapKey_upgradeStatus,""+arguments[0]);
}
module.exports.upgradeStatus = upgradeStatus;
//当前定位
var mapKey_dingwei = "dingwei";
var defaultDingwei = {"longitude":"114.064518","latitude":"22.548607","address":"广东省深圳市","cityName":"深圳市"};
function currentLocation(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_dingwei)){
			var value = cacher.loadData(mapKey_dingwei);
			if(!value || value==null || value==="undefined"){
				return defaultDingwei;
			}else{
				return value;
			}
		}else{
			return defaultDingwei;
		}
	}
	if(arguments[0]===""){
		cacher.removeData(mapKey_dingwei);
		return;
	}
	cacher.saveData(mapKey_dingwei,""+arguments[0]);
}
module.exports.currentLocation = currentLocation;
//起点位置
var mapKey_startPoint = "dingweiStartPoint";
var startPoint = "22.548607,114.064518";
function currentStartPoint(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_startPoint)){
			var value = cacher.loadData(mapKey_startPoint);
			if(!value || value==null || value==="undefined"){
				return startPoint;
			}else{
				return value;
			}
		}else{
			return startPoint;
		}
	}
	if(arguments[0]===""){
		cacher.removeData(mapKey_startPoint);
		return;
	}
	cacher.saveData(mapKey_startPoint,""+arguments[0]);
}
module.exports.currentStartPoint = currentStartPoint;

/** 是否已展示了荣誉系统上线提示:1-是,其它-否 **/
var mapKey_honorPage_isShow = "honorPage_isShow";
function honorPageIsShow(){
	if(arguments.length==0){
		if(cacher.hasData(mapKey_honorPage_isShow)){
			var value = cacher.loadData(mapKey_honorPage_isShow);
			if(!value || value==null || value==="undefined"){
				return "";
			}
			return value;
		}else{
			return "";
		}
    }
    if(arguments[0]===""){
    	cacher.removeData(mapKey_honorPage_isShow);
        return;
    }
    cacher.saveData(mapKey_honorPage_isShow,""+arguments[0]);
};
module.exports.honorPageIsShow = honorPageIsShow;